using B.S.Base.Read.API.新文件夹;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using System.Reflection;
using WEBAPI.API;
using WEBAPI.Indaseture;
using WEBAPI.Indaseture.Infasetures;
using WEBAPI.Indaseture.Inmoment;


var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
// 配置Swagger
builder.Services.AddSwaggerGen(
c =>
    {
        c.IncludeXmlComments(AppContext.BaseDirectory + "B.S.Base.Read.API.xml", true);
        //jwt鉴权在swagger中的应用
        c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme()
        {
            Description = "在下框中输入请求头中需要添加Jwt授权Token：Bearer Token",
            Name = "Authorization",
            In = ParameterLocation.Header,
            Type = SecuritySchemeType.ApiKey,
            BearerFormat = "JWT",
            Scheme = "Bearer"
        });
        c.AddSecurityRequirement(new OpenApiSecurityRequirement
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id = "Bearer"
                            }
                        },
                        new string[] { }
                    }
                });
});

//builder.Services.AddSwaggerGen(x=>
//{
//    x.IncludeXmlComments(AppContext.BaseDirectory + "B.S.Base.Read.API.xml", true);
//});

builder.Services.AddJWT(builder);
builder.Services.AddDbContextService<MyDbContext>(builder.Configuration.GetConnectionString("Conn"), true);


//扩展类
builder.Services.Addservices();
var app = builder.Build();
//判断在开发的环境下可允许访问Swagger
// Configure the HTTP request pipeline.
//if (app.Environment.IsDevelopment())
//{
    app.UseSwagger();
    app.UseSwaggerUI();
//}
//跨域
app.UseCors(x => x.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod());
app.UseAuthentication();
app.UseAuthorization();
// 鉴权


app.MapControllers();

app.Run();
